cleaner code, comments added