Using array

Clean up spaghetti code