Cleaned code (warnings etc)

Fixes #1098 #1099 #1108