fixed a memory leak, cleaned some code...