major update and refactor