second appraoch- cleaned up code