Bugs fixed. Cleaned up code.