bug fixing and working random gen