Exception handling added and mnore checks and reason-outputting/debugging.