refactored refresh function & added input