general code cleaup and reorganisation