Fixed mistakes, finalized code