Added error logging. Also changed file-path building