improved getkpg() to clea page only when needed