Merged Sean's new functions with my changes