Cleaned up script and added more comments