Made onFrame a liiittle smarter...also refactored it.