Various fixes

Remove using global variables. Set debug and release routines