Make this code work better?