Fixed incorrect order of operations, added 'clear', fixed calloc for stack