Code messy but functional :)