Updated Gordula database tables code

I've cleaned up the code and made it a little more robust.