added code and bugs