reimplemented some changes I made.