working, tidied code.

Signed-off-by: fdavison <fred.davison84@gmail.com>