manually merged some code