Cleanups

The code was really ugly.