Separated the logic some more and added comments