Several code updates to fix issues