Minor code cleanup, improved contracts