HUGE code refactor (#3)