Code cleanup

Removed some redundancies and improved readability.