added check for invalid arguments; removed debug echos