Refactor to take command line argument for N