Various code fixes