Flask logic