Cleaned up a bit, fixed a few bugs.