Fixed scrollbar issue in popup windows and minor code tidy ups and commenting