merged puga's code