Cleaned up script to remove redundancy