warning fixes and code tidying