better refactoring and tested with topaz