Revert "fixes memory issue as well as re-orders somethings."

This reverts commit fa557186ad5c4c30ddcaecf003097f24e7b7798b.