fixed #2 and rename some vars