Fixed todo bugs and added onbeforeunload sync