made minor changes based on tips from stucox