some code improvements, bugfixes, coding style