refactoring with firebase security fixes