Improved check function & bug fixes