finished code, debugging now