fixed some bugs, refactored and added support for char