final version, all working