Encapsulated code in a function, added a few options