Cleanup and improvements

Cleaned up code, improved comments and aplied some small fixes to the
code.