Bug fixes
Added better error handling