bug fixes, refactoring etc