Modified grab function and fixed some errors