RDS Support

Now supports RDS. Might require a bit of finetuning. A set of fresh eyes would help find any issues.
It is based on #17 which is based on other PR's.
It also fixes a logical bug in that PR.