cls: adding nan checks and fixing problem with mirror scaling