clean up: add more comments and make set_sprite and get_sprite more efficient