Added check for storage space, also fixed a few minor bugs