Convert gem to engine, add tests, fix behavior to pass tests