should resolve #350

and some code refactoring