Made some corrections based on IDEA's inspection of the code