added more exception handling, script fully builds for most cases