Modified version to suit my own needs