re-factored for re-usability and better conventions