Code cleanup and option parsing