Added input sanitasion and fixed offset