code cleaned; memory bug fixed