added dynamic memory allocation to the scanner