improved version shorter code