Added a few missing codes
'Privatized' some global variables