Cleaner code, added comments