Sharp swings to first quarterly net profit in over two years