reverting some of my code and fixed #1322 properly