Changed several checks and added several comments