Miscellaneous algorithms..