Fixed failing tests and added SCRIPT_NAME == nil check