not the most efficient but it works