finished code for rejection method