added invert method; polished some stuff up (Flask side)