Problem solved, but there's a little memory leak