Corrected some errors, added examples and complexity analysis