throwing explicit errors on unexpected behaviour