Correcting bugs of implementation and adding some improvements.