Added comments to make code clearer and changed to >=s and <=s and whatnot