implement basis finding algorithm