added exception to log
fixed possible null pointer exception
some small tweaks and error fixing