added a bit more documentation and comments