fix randomness extraction
start refactoring...