some cleanup and re-organisation