Fixing some really shoddy code