working on refactoring - its ugly