basic code works now, memory problems