adding Null Pointer Exception, changing the exception handling code and moving some stuff