added working code from test project