Fixed duplicating scope issue and other enhancments