made several necessary changes, before was broken