Fixed miscellaneous bugs