almost finished code