cleanup & bugfixes

cleanup continued and bug fixes