added function docs and some coding style fixes