Misc. Algorithms Implementation