Corrected mistakes - now compiles (not tested)