Refactored and updated to work with version 31.8.2012