major code refactor pt 1