Messy code, not working