faster checking, corrected function and function implementation