Updated main.py to use new validpos function