Adding some documentation

A little refactoring and some documentation