Code cleanup

Simplified a few things, must add comments later on.