I've pushed a possible refactoring. @tojofo wrap your eyes around that.