refactor, fix bugs
allow non-debug build
cleanup