implemented simpler code to fix #2