some simple algorithms