final code implementation

bug fixes