working code based on BarkingOwl Design Series ( http://timduffy.me/blog )