Code cleanup based on aochagavia's suggestions