refactoring split engine code into three files: engine, stack and utils