fixed-up code, now it compiles. not functionally tested yet...