Simplified code
Fixed some minor issues