not the best implementation but works for me