fixed small errors and cleaned up code