making it work on both SQLS and PS1...
Phil's changes inserted