Cleanup and bug fix