simplified and shortened the code