Daniel/bug fixes and clean up