Fixed some memory problems.
Buffer length problem resolved when contructing filenames
Added some NPD tests