Cleaned up and explained some odd code