Took Ben Balter's stuff and modified it for my needs