Cleaned up the code and implemented isLegalCapture