optimizations + fix cursor resetting