add damId as select query condition
added small refactoring