finished implementation of code to follow documentation. Also made fixes as per pr comments