[CLEANUP] - refactor and cleanup some nasty code.