updated code

need to debug user defined or the database.
and make comments on the code.