Fixes code style issues and small bugs. Closes issue #12, #18, #11 and basis for #3 and framework for #4.