fixed several bugs and incomplete stuff