re-organise code