fixed off by one error
moved core logic to drawengine module, added tests