More general cleanup and adding code develped in recent project