Cleaned up sum calculation