refactor and minimize errors