some small changes

Hey, here is some code style changes, additional checks, scoping etc.