Added clearer error messages, better structure