seems to work & refactored