Almost finished code, some debugging