Lots of edge cases fixed. Example added