bug fix and temp refactoring