Fixed several bugs, still testing implementation