fixed bug and added output