Cleaning up bugged code