Fixing dialog cancel bug and incorrect conditional on getPatternFromDB method