Refatoring Code. Fixing Bug authetication.