refactor engine
add inline documentation