added queue function and updated code to work with queue