Refractored some code in order to fix some issues.
close #29