updated code structure, added handler function for input