refractored some stuff, wrote CLI test