Code works on boot loader but not when directly programmed

You have of course added code to deal with the restart and then transfer control to your sketch? Haven't you?

Mark