fixed #502, #511, #517