Fixed bounds to check if valid correctly and to fix errors