Cleanup and bug fixes