added simple profiling
fixed serious memory bug
improved performance