Working version with command line arguments