almost finished implementation