add file extension check and fix some bugs