refactor engine and view code to make them more generic