Cleaned up most of the code. Still need to add more comments.