Cleaned up code, fixed small errors