Multiple code analysis problems in this function, simple ones most of them are the same