code cleanup and reorganisation