Fixed several bugs, added some features