passes all tests now
smaller implementation