Latest version of code

This contains everything except for the UI which is committed by venky