Fix bug in assertion logic
Split across more files