Cleaning up code

Not tested, but nothing significant got changed, general code cleanup for readability.