Added lots of specs and some error handling here and there