Refactoring the code for helping #65 and fixing #70.