cleaned up and refactor