Added PTR handling.. some bug fixes