Added complete implementation for #1