Fixed misc bugs