code review and bugfixes