better figure inclusion code , better error checking logic