Added some exception handling. Marked all the functions throwing