some modifed code to enable to use in personal project