Updated for 0.13 and refactored