finished code, need to debug