working but need refactoring