code update by @royfrancis