added more checks, corrected