Cleaned up function and got rid of all old dead code that was no longer
doing anything.