Cleanup source code

Collection of style cleanup and addition of contracts to source.