Cleaning and documentation for issue #14

Done som cleaning and sepparation of code into a superclass to ease
maintenence. Also documented some code for future use. This also fixes
issue #14