function implement finished, ready to debug