Polished code

Made code more readable and added/corrected comments