Fixing issues in flow, writing tests