updated with new code from gaut
updated with new code from gaut