This is a basic implementation that works.
fixed errors in the previous commit