bug fixes, optimization, refactor, cleanup