changed api and simpleized code