Added some comments, changed move checking to a function