Add tool for random testing and fix couple bugs