Replace asserts with exceptions
Refactor