Code messy, but 'working'