bug fixes and small improvements