adding global parameters and fixing memory issues