Made code more concise and updated README with examples

The code does exactly what it does before but in a different way. The new way is much shorter.

Also added an examples to the README.