TODO: refactor this crap -_-