Cleaned up and formatted for my own purposes.