Replaced assertions with proper error & exit