added boundary handling in pos