Added most of the library from movable-type.co.uk