Added bounds checking and end game criteria.