Weird stuff happening. Fixed code