restructured code
initializing all arrays