a bit of clean up and defensive coding...