Some minor changes to improve readability, plus make error checking more permissive.