add more checks, along with bugfix