Found this on StackOverflow, fits the bill. Made a few modifications to ease abstraction a bit. Perhaps use with a config file later?