Change some constants to defines and make the globals static
Fix some warnings