fixed handle issue + optimizations