freeing allocated space. minor improvements. validation works.