Implemented most functions other than top.