finished. TO DO: review and code style