HUGE REFACTOR OMFG :-(