Cleaned up, added comments and fixed some problems.