refactored a bit, added sample code