Added exceptions and a little bit more checks