Added castling logic, switched to using flags for castling for performance and readability