Improve check function