basic implementation of algorithm