Added better error returns, and fixed some bugs related to models