Shortened and simplified code.
Fixed small bug.