Test added and bugs fixed