Fixed bugs, clearer error messages