Fixes bunch of possible crashes. Converts run.rb into executable run that can take input parameters.