fix #427 and some bugs in validation of flow typing