I've already answered a similar question on StackOverflow so I'll repeat what a I said there.
The following may not solve your problem completely but it should give you some pointer to start.
The first problem that you are facing is the disproportio...