Added more error handling and no disk write, ready for testing