simplified some parts of the code for clarity
remove init function from listener to simplify use.