Fix bugs from previous commit