Everything works -- still needs to be optimized (mem leak)