Can I make this code shorter?