Added some error handling for low space size, zero division