refactor: add preconditions checks