reorganised code