Clean up and bugfix