Little code clean up and refactoring, adding doc comments