fixed bug in tofrom method