Cleaned code, comments, reorganised some of the logic (to make it logical!)