code duplication and potentical security breach fixed.