fixed small bug, cleaned up code