now takes filename from cmd args and fixed ptr logic