finalize variables and optimize imports