Latest working code

This is the latest working code though lacks unit tests