refactor as per @ajb