Implementation of basic algorithms