Cleanup and fixes #560