Cleaning code and catching few errors