Added some additional checks and variables