major code refactor