optimize kperlin a bit