initial commit of working code
removed memory abuse