Fully working sparse reconstruction and detection. Fixed all the problems, errors and memory leaks. Optimised and commented the code.