integrated all necessary code