Minor code fixes/optimization