fixed int casting and error nil comparission