general cleanup of code to make it slightly neater