Switched to explicit template handlers and various bug fixes