Full implementation. Ready for testing