Add db argument and make cood look better ;P

Here you are. :)

I've only added the $db object as argument. You should now know how it goes from here. ;-)
If you still have some question, feel free to ask me. :)

PS: You didn't thought, I would do this, did you?