tidying up, refactored a bit.