Added some checks

Maked the code cleaner