CLEANED coded, added comments