improved #id handling