Implemented winning condition and fixed some bugs