refactor and tide up