work pen algorithm