fixed several bugs