some tiny algorithms