updated pseudocode, added checks for board edge cases