Code cleaned, added some controls and redirects