Little refactoring, fixed some bugs, added some features