add more boundary checks