Fix multiple bugs