my version
refactoring almost complete